<%-- 
    Document   : valida_form
    Created on : 16/04/2011, 17:20:40
    Author     : Luis Marcelo
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="login.PMFlogin"%>
<%@page import="login.Usuario"%>
<%@page import="java.util.List"%>
<%@page import="javax.jdo.PersistenceManager"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Valida Formulário</title>
    </head>
    <body>


        <%
        String usuarioLogin = request.getParameter("usuario");
        String senhaLogin = request.getParameter("senha");

        PersistenceManager pmLogin = PMFlogin.get().getPersistenceManager();
        String query = " select from " + Usuario.class.getName() + " where loginUsuario == '"+ usuarioLogin +
               "' && senhaUsuario == '"+ senhaLogin + "'";

        List<Usuario> usuarios = (List<Usuario>) pmLogin.newQuery(query).execute();        
        
        if (usuarios.isEmpty()) {
        %>
           <jsp:forward page="erro.jsp"/>
        <%
        } else {
        %>        
           <jsp:forward page="pois.jsp"/>
        <%
        }
           pmLogin.close();
        %>
    </body>
</html>
